package orthoplanner.com.google.code.eventhandlers;


import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFileChooser;

import orthoplanner.com.google.code.ui.ImageViewer;
import orthoplanner.com.google.code.utils.ImageFileFilter;


public class ImageBrowseHandler extends MouseAdapter {
	JFileChooser jfc;
	ImageViewer imgViewer;

	public ImageBrowseHandler(ImageViewer imgViewer) {
		this.imgViewer = imgViewer;
		jfc = new JFileChooser();
		jfc.setDialogTitle("Select the X-Ray");
		jfc.setFileFilter(new ImageFileFilter());
		//jfc.set
		jfc.setAcceptAllFileFilterUsed(false);
		jfc.setVisible(true);

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		super.mouseClicked(arg0);
		int retValue = jfc.showOpenDialog(jfc);
		if (retValue == JFileChooser.APPROVE_OPTION) {
			System.out.println(jfc.getSelectedFile().getAbsolutePath());
			imgViewer.uploadImage(jfc.getSelectedFile());

		}

	}

}
